package com.itany.boot.config;

import com.itany.boot.interceptor.LogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/5/27 9:03
 * Version:1.0-SNAPSHOT
 * Description:
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {

    /**
     * 配置直接访问视图
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/showLogin").setViewName("backend/login");
        registry.addViewController("/showMain").setViewName("backend/main");
    }

    /**
     * 配置拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截器是谁
        registry.addInterceptor(new LogInterceptor())
                // 拦截谁,方法可以多次调用
                // 参数可以是可变长字符串,也可以是集合
                .addPathPatterns("/**")
                // 不拦截谁,方法可以多次调用
                // 参数可以是可变长字符串,也可以是集合
                .excludePathPatterns("/log/add")
                .excludePathPatterns("/log/remove","/log/modify");
    }
}
